﻿import { generalRemove } from '@/api/common'

// api 批量删除方法
/**
 *
 *
 * @param data
 * @param location
 * @param self
 */
export function generalRemoveR(data, location, self) {
  self.$confirm(self.$t('common.permanentlyDelete'), self.$t('common.prompt'), {
    confirmButtonText: self.$t('common.confirm'),
    cancelButtonText: self.$t('common.cancel'),
    type: 'warning'
  }).then(() => {
    var dataTemp = []
    for (var i = 0; i < data.length; i++) {
      dataTemp.push(data[i].id)
    }
    var ids = {
      ids: dataTemp.join()
    }
    console.log(ids)
    generalRemove(ids, location).then(response => {
      console.log(response)
      if (response.data.code === '0000') {
        // this.dialogFormVisible = false
        self.$notify({
          title: self.$t('common.succeed'),
          message: self.$t('common.del') + self.$t('common.success'),
          type: 'success',
          duration: 2000
        })
        self.handleFilter()
      } else {
        if (response.data.code === '5000') {
          self.$notify({
            title: self.$t('common.failed'),
            message: '系统错误,请联系管理员',
            type: 'info',
            duration: 2000
          })
        } else {
          self.$notify({
            title: self.$t('common.failed'),
            message: response.data.content,
            type: 'info',
            duration: 2000
          })
        }
      }
    })
  }).catch(() => {
    // this.getList()
    self.$message({
      type: 'info',
      message: self.$t('common.cancelDelete')
    })
  })
}
